package com.dataextend.service;


import com.alibaba.fastjson.JSONObject;
import com.dataextend.mapper.cluster.EventListMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 行为事件下拉菜单
 */
@Slf4j
@Service
public class EventListService {
    @Autowired
    EventListMapper eventListMapper;


    /**
     *  行为事件下拉菜单
     */
    public List<JSONObject> eventList(){
        List<JSONObject> eventList = eventListMapper.eventList();
        List<JSONObject> returnResult = new ArrayList<>();
        for (JSONObject obj : eventList){
            JSONObject detail = new JSONObject(true);
            detail.put("event_name", obj.getString("event_name"));
            detail.put("event_code", obj.getString("event_code"));
            returnResult.add(detail);
        }

        return returnResult;
    }


    /**
     *  细分维度[设备属性/用户属性] 下拉菜单
     */
    public List<JSONObject> attributeList(){
        List<JSONObject> attributeList = eventListMapper.attributeList();
        List<JSONObject> returnResult = new ArrayList<>();
        for (JSONObject obj : attributeList){
            JSONObject detailInfo = new JSONObject(true);
            detailInfo.put("property_name", obj.getString("property_name"));
            detailInfo.put("property_code", obj.getString("property_code"));
            detailInfo.put("property_type_code", obj.getString("property_type_code"));
            detailInfo.put("property_type_name", obj.getString("property_type_name"));
            returnResult.add(detailInfo);
        }
        log.info("--->细分维度[设备属性/用户属性] 下拉菜单:{}" , returnResult);
        return returnResult;
    }


    /**
     *  用户标签下拉菜单 标签筛选用户标签下拉1 2 3级菜单
     */
    public JSONObject dropDownList1(String level1){
        JSONObject returnResult = new JSONObject(true);
        List<JSONObject> list = eventListMapper.dropDownList1(level1);
        returnResult.put("list", list);
        returnResult.put("total", list.size());
        return returnResult;
    }

    public JSONObject dropDownList2(String level1, String level2){
        JSONObject returnResult = new JSONObject(true);
        List<JSONObject> list = eventListMapper.dropDownList2(level1, level2);
        returnResult.put("list", list);
        returnResult.put("total", list.size());
        return returnResult;
    }


    /**
     *  用户行为分析 下拉菜单过滤条件筛选Key Value
     */
    public JSONObject dropDownListKey(){
        JSONObject returnResult = new JSONObject(true);
        List<JSONObject> list = eventListMapper.dropDownListKey();
        returnResult.put("list", list);
        returnResult.put("total", list.size());
        return returnResult;
    }


    public JSONObject dropDownListValue(String level_2_name){
        JSONObject returnResult = new JSONObject(true);
        List<JSONObject> list = eventListMapper.dropDownListValue(level_2_name);
        returnResult.put("list", list);
        returnResult.put("total", list.size());
        return returnResult;
    }


    public JSONObject dropDownList(){
        JSONObject returnResult = new JSONObject(true);
        List<JSONObject> list = eventListMapper.dropDownList();
        returnResult.put("list", list);
        returnResult.put("total", list.size());
        return returnResult;
    }

}
